//
// Created by dxyinme on 2021/10/9.
//

#include "serializer.h"
namespace Vsort {
namespace FileSort {

Serializer::Serializer(SerializerType s_type) {
  serializer_type = s_type;
}

Serializer::~Serializer() {}

size_t Serializer::GetUnReadItemNum() {
  return unread_buf.size();
}

int Serializer::ReadFromCharPtr(char *s) {
  if (serializer_type == SerializerType::DivideOperator) {
    return ReadFromCharPtrInDivideOperator(s);
  }
  return 0;
}

int Serializer::ReadFromCharPtrInDivideOperator(char *s) {
  int i = 0, last_point = -1;
  std::string str;
  while (s[i] != '\0') {
    if (s[i] != '\n') {
      str.push_back(s[i]);
    } else {
      last_point = i;
      unread_buf.push_back(str);
      str.clear();
    }
    i++;
  }
  return last_point;
}

const std::deque<std::string>& Serializer::UnReadBufRef() const {
  return unread_buf;
}


}
}
